package simpleGeom;

import java.awt.geom.Line2D;


public class DelaunayMath {
	static double minValue=0.000000001;
	
	
	public static boolean isOnline(HasPos2D a, HasPos2D b, HasPos2D p){
		
		double d=Line2D.ptSegDist(a.getX(), a.getY(), b.getX(), b.getY(), p.getX(), p.getY());
		if (d<0.001)return true;
		return false;
	}
	public static boolean isConvex(HasPos2D a, HasPos2D b, HasPos2D c, HasPos2D d) {
		// points online = already concave
		if (relativeCCW(a, b, c) != Vec2D.CCWLEFT)
			return false;
		if (relativeCCW(b, c, d) != Vec2D.CCWLEFT)
			return false;
		if (relativeCCW(c, d, a) != Vec2D.CCWLEFT)
			return false;
		if (relativeCCW(d, a, b) != Vec2D.CCWLEFT)
			return false;
		return true;
	}
	public static int relativeCCW(HasPos2D p0, HasPos2D p1, HasPos2D p2) {
		HasPos2D v1=Vec2D.sub(p0, p1);
		HasPos2D v2=Vec2D.sub(p0, p2);
		double cA= ((v1.getX()) * (v2.getY()) - (v2.getX()) * (v1.getY()));
		if (Math.abs(cA)<minValue)return 0;
		if (cA<0)return Vec3D.CWRIGHT;
		return  Vec3D.CCWLEFT;
	}
	
	public static double parallelArea(HasPos2D p0, HasPos2D p1, HasPos2D p2) {
		HasPos2D v1 = Vec2D.sub(p0, p1);
		HasPos2D v2 = Vec2D.sub(p0, p2);
		return ((v1.getX()) * (v2.getY()) - (v2.getX()) * (v1.getY()));
	}
}
